var page = 'pressureList'

$(document).ready(function () {
    getData(p,getValue(page))
});

function getData(p,arr){
    // console.log(arr);
    $.ajax({
        url: global.apiUrl + '/admin_get_user_xueya',
        type: 'GET',
        dataType: 'json',
        data: {
            p: p,
            start_time: arr[0],
            end_time: arr[1],
            type: arr[2],
            userid: $('#searchInput').val()
        },
        header: {
            'content-type': 'application/json' //默认值
        },
        success: function(res){
            console.log(res)
            if(arr[6] == 1){
                //正序
                res.content = res.content.reverse()
            }
            var html = ''
            for(var i in res.content){
                html += `<tr>
                            <td>
                                <div class="userItem" onclick="findId(${res.content[i].user_id})">
                                    <text>${res.content[i].content.nickname}</text>
                                    <text>${res.content[i].content.sex} ${res.content[i].content.height}cm</text>
                                    <text style="margin-bottom:0">ID: ${res.content[i].user_id}</text>
                                </div>
                            </td>
                            <td>${res.content[i].height}</td>
                            <td>${res.content[i].low}</td>
                            <td>${res.content[i].heart}</td>
                            <td>${res.content[i].addtime}</td>
                            <td>${res.content[i].eid?res.content[i].eid:'-'}</td>
                            <td>
                                <a href="pressureChart.html?id=${res.content[i].user_id}" class="btn btn-white btn-sm">趋势</a>
                            </td>
                        </tr>`
            }
            $('#userList').html(html)
            $("#page").paging({
                pageNo: p,
                totalPage: Math.ceil(res.count/20),
                totalSize: res.count,
                callback: function(num) {
                    // console.log(num)
                    getData(num,getValue(page))
                }
            })
        }
    })
}

function sort(obj){
    getData(p,getValue(page))
}

function clickBtn(){
    getData(p,getValue(page))
}

function findId(id){
    // console.log(id)
    $("#searchInput").val(id);
    getData(p,getValue(page))
}